package cn.zhouchao.basic.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult { //封装的一个异步操作工具类

    private Boolean success;

    private String msg;

    private Object resultObj;
    // 添加一个新的有参数（Object resultObj）的
    public AjaxResult success(Object resultObj){
        return AjaxResult.me().setSuccess(true).setMsg("操作成功").setResultObj(resultObj);
    }
    public AjaxResult success(){
        return AjaxResult.me().setSuccess(true).setMsg("操作成功");
    }

    public AjaxResult fail(){
        return AjaxResult.me().setSuccess(false).setMsg("操作失败");
    }

    public AjaxResult fail(String msg){
        return AjaxResult.me().setSuccess(false).setMsg(msg);
    }

    public static AjaxResult me(){
        return new AjaxResult();
    }

    public AjaxResult setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public AjaxResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    // 新的构造
    public AjaxResult setResultObj(Object resultObj) {
        this.resultObj = resultObj;
        return this;
    }

}
